package cn.yuanqiao.web.controller.archive.bianyan;

import cn.yuanqiao.archive.bianyan.domain.YqDaGerenKu;
import cn.yuanqiao.archive.bianyan.domain.YqDataZhuantiGern;
import cn.yuanqiao.archive.bianyan.service.IYqDaGerenKuService;
import cn.yuanqiao.common.web.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.web.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 档案资源
 *
 * @ProjectName: JZSDAS
 * @Package: cn.yuanqiao.web.controller.archive.bianyan
 * @ClassName: YqDaGerenKuController
 * @Author: lenovo
 * @Description: hbWang
 * @Date: 2023/9/18 17:20
 * @Version: 1.0
 */
@RestController
@RequestMapping("/archive/da/library")
public class YqDaGerenKuController extends BaseController {
    @Autowired
    private IYqDaGerenKuService yqDaGerenKuService;

    /**
     * 查询档案资源库列表
     */
    @PreAuthorize("@ss.hasPermi('archive:da:library:list')")
    @GetMapping("/list")
    public TableDataInfo list(YqDaGerenKu yqDaGerenKu) {
        startPage();
        List<YqDaGerenKu> list = yqDaGerenKuService.selectYqDaGerenKuList(yqDaGerenKu);
        return getDataTable(list);
    }

    /**
     * 获取档案资源库详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(yqDaGerenKuService.selectYqDaGerenKuById(id));
    }


    /**
     * 新增档案资源库
     */
    @Log(title = "档案资源库", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('archive:da:library')")
    @PostMapping
    public AjaxResult add(@RequestBody List<YqDaGerenKu> yqDaGerenKus) {
        return toAjax(yqDaGerenKuService.insertYqDaGerenKu(yqDaGerenKus));
    }

    /**
     * 添加至专题库
     *
     * @param yqDataZhuantiGern
     * @return
     */
    @PreAuthorize("@ss.hasPermi('archive:da:library:zt:add')")
    @Log(title = "档案资料添加至专题库", businessType = BusinessType.INSERT)
    @PostMapping(value = "/zt/add")
    public AjaxResult addZT(@RequestBody List<YqDataZhuantiGern> yqDataZhuantiGern) {
        return toAjax(yqDaGerenKuService.insertYqZhuanTiList(yqDataZhuantiGern));
    }

    /**
     * 修改档案资源库
     */
    //  @PreAuthorize("@ss.hasPermi('archive:DA_KU:edit")
    @Log(title = "档案资源库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YqDaGerenKu yqDaGerenKu) {
        return toAjax(yqDaGerenKuService.updateYqDaGerenKu(yqDaGerenKu));
    }

    /**
     * 退回至个人库
     *
     * @param gerenIds
     * @return
     */
    @PreAuthorize("@ss.hasPermi('archive:da:library:zt:remove')")
    @Log(title = "退回至个人库", businessType = BusinessType.DELETE)
    @DeleteMapping(value = "/zt/remove/{gerenIds}")
    public AjaxResult removeZT(@PathVariable String[] gerenIds) {
        return toAjax(yqDaGerenKuService.deleteYqZhuanTiByIDs(gerenIds));
    }

    /**
     * 添加公共库
     *
     * @param gerenIds
     * @param typeState
     * @return
     */
    @PreAuthorize("@ss.hasPermi('archive:da:library:edit:communal')")
    @Log(title = "添加和移除至公共库", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/edit/communal")
    public AjaxResult editCommunal(@RequestParam("gerenIds") String[] gerenIds, @RequestParam("typeState") String typeState) {
        return toAjax(yqDaGerenKuService.communalUpdate(gerenIds, typeState));
    }

    /**
     * 移除公共库
     *
     * @param gerenIds
     * @param typeState
     * @return
     */
    @PreAuthorize("@ss.hasPermi('archive:da:library:removeCommunal:communal')")
    @Log(title = "添加和移除至公共库", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/remove/communal")
    public AjaxResult removeCommunal(@RequestParam("gerenIds") String[] gerenIds, @RequestParam("typeState") String typeState) {
        return toAjax(yqDaGerenKuService.removeCommunal(gerenIds, typeState));
    }

    /**
     * 删除档案资源库
     */
    @PreAuthorize("@ss.hasPermi('archive:da:library:remove')")
    @Log(title = "档案资源库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(yqDaGerenKuService.deleteYqDaGerenKuByIds(ids));
    }
}
